package totask.controller;

import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import totask.response.ResponseData;
import totask.service.impl.LoginServiceImpl;
import totask.vo.LoginInfoVO;
import totask.vo.LoginUserInfoVO;

import javax.validation.Valid;
import java.util.Objects;


@Api(tags = "用户登录")
@RestController
@RequestMapping("/sys")
public class LoginController {

@Autowired
    LoginServiceImpl loginService;

    @ApiOperation("根据账号或密码登录")
    @PostMapping("/login")
    public ResponseData<LoginUserInfoVO> LoginUser(@RequestBody @Valid LoginInfoVO loginInfoVO) {

        LoginUserInfoVO data = loginService.LoginUser(loginInfoVO).getData();
        //
        if(Objects.isNull(data.getUserInfo())) {
            return new ResponseData<LoginUserInfoVO>().fail("登录失败");
        }else {
            //返回前端
            return new ResponseData<LoginUserInfoVO>().success(data);
        }

    }
}
